<template>
  <footer class="todo-footer" v-if="todos.length > 0">
    <input
      type="checkbox"
      :checked="doneCount === todos.length && todos.length > 0"
      @change="$emit('toggle-all', $event.target.checked)"
    />
    <div>已办事项{{ doneCount }}/全部事项{{ todos.length }}</div>
    <button @click="$emit('clear-done')">清除已办</button>
    <button @click="$emit('clear-all')">清除所有</button>
  </footer>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  todos: {
    type: Array,
    required: true,
  },
})

// 计算已完成的任务数量
const doneCount = computed(() => {
  return props.todos.filter((todo) => todo.done).length
})

defineEmits(['toggle-all', 'clear-done', 'clear-all'])
</script>

<style scoped>
.todo-footer {
  display: flex;
  align-items: center;
  margin-top: 20px;
  padding: 10px 40px;
  background-color: #87ceeb;
}
.todo-footer div {
  flex: 1;
  margin-left: 20px;
}
.todo-footer button {
  margin-left: 10px;
  padding: 5px 10px;
  border: none;
  border-radius: 3px;
  background-color: #ff6700;
  color: white;
  cursor: pointer;
}
.todo-footer button:hover {
  opacity: 0.8;
}
</style>
